﻿using Kevin.Comm.Utility.Crypto;
using Kevin.Shop.Business.Core.Components.Responser;
using Kevin.Shop.Business.Service.Entity.Helper;
using Kevin.Shop.Business.Service.Entity.StoreManagement.Enumerations;
using RiderShop.Mobile.Common.Component;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RiderShop.Mobile.Modle
{
    public class FindPasswordModel
    {
        public string Message { get; set; }

        public string UserName { get; set; }

        public string VerifyCode { get; set; }

        public string CellPhone { get; set; }

        public FindPasswordAction ActionType { get; set; }

        public static string VerifyCodeKey = "VerifyCode";
        public static bool CheckVerifyCode(string verifyCode)
        {
            verifyCode = SystemEncrypt.Encrypt(verifyCode.ToLower());
            string validCode = Kevin.Shop.Business.Core.Components.Cookie.KevinCookieManager.Get(VerifyCodeKey);

            bool flag = string.Compare(validCode, verifyCode, false, System.Globalization.CultureInfo.InvariantCulture) == 0;
            Kevin.Shop.Business.Core.Components.Cookie.KevinCookieManager.Remove(VerifyCodeKey);
            return flag;
        }

        public Kevin.Shop.Business.Core.Member.UserBasicInfo UserInfo { get; set; }

        public ServiceResponser FindPasswordByEmail(string userName, string email)
        {
            var Result = RestfulHelper.UpdateWithQueryString(SiteUrl.FormatUrl("Common_ResetUserPassword", userName, email));
            return Result;
        }

        public static ServiceResponser SendSMSAuthentiCode(int userId, string cellPhone, SMSSendType smsType = SMSSendType.ChangePassword)
        {
            var Result = RestfulHelper.UpdateWithQueryString(SiteUrl.FormatUrl("SystemTools_SendSMSCode", userId, 0, cellPhone, (int)smsType));
            return Result;
        }

        public static ServiceResponser VefifySMSAuthentiCode(int userId, string smsCode, SMSSendType smsType = SMSSendType.ChangePassword)
        {
            var Result = RestfulHelper.UpdateWithQueryString(SiteUrl.FormatUrl("SystemTools_VefifySMSCode", userId, smsCode, (int)smsType));
            return Result;
        }
        public static ServiceResponser UpdateUserVerifiedCellPhone(int userId, string cellPhone, string smsCode)
        {
            var Result = RestfulHelper.UpdateWithQueryString(SiteUrl.FormatUrl("Common_UpdateUserVerifiedCellPhone", userId, cellPhone, smsCode));
            return Result;
        }
    }

    public enum FindPasswordAction
    {
        //忘记密码重置
        FindPassword=0,

        //只绑定手机号
        BindingCellPhone = 1,

        //绑定手机号并设置密码
        SetPassword = 2,

        //解除绑定手机号
        UnBindingCellPhone = 3,

        //重新绑定手机号
        ReBindingCellPhone = 4
    }
}
